package com.headingdata.loop;

public class ForDemo2 {
    public static void main(String[] args) {
        //for循环批量产生数据
        for(int i = 1; i <= 100; i++){
            System.out.println(i);
        }

        //求1-100的和
        int sum = 0;
        for (int i = 1; i <= 100; i++){
            sum += i;
        }
        System.out.println(sum);

        //求1-100奇数的和
        int sum1 = 0;
        for (int i = 1; i <= 100; i+=2){
            sum1 += i;
        }
        System.out.println(sum1);

        int sum2 = 0;
        for (int i = 1; i <= 100; i++){
            if( i % 2 != 0){
                sum2 += i;
            }
        }
        System.out.println(sum2);
    }
}
